/**
 * 344. 反转字符串
 * https://leetcode-cn.com/problems/reverse-string/
 */
public class Solutions_344 {
    public static void main(String[] args) {
//        char[] arr = {'h', 'e', 'l', 'l', 'o'};  // output: {'o', 'l', 'l', 'e', 'h'}
        char[] arr = {'H', 'a', 'n', 'n', 'a', 'h'};
        // output: {'h', 'a', 'n', 'n', 'a', 'H'}

        reverseString(arr);
        System.out.println(arr);
    }

    public static void reverseString(char[] s) {
        int left = 0, right = s.length - 1;
        while (left < right) {
            char temp = s[left];
            s[left] = s[right];
            s[right] = temp;
            left ++;
            right --;
        }
    }
}
